﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using OPMS_V1.BOL;
using System.IO;

namespace OPMS_V1.Public
{
    public partial class Build : System.Web.UI.Page
    {
        //Variables for Property Address Details
        #region Auto Implemented Properties for Mode Share, Rent and Sell
        
        /// <summary>
        /// Autoimplemeted property for StreetName
        /// </summary>
        public String streetname
        { get; set; }
        
        /// <summary>
        /// Autoimplemeted property for Area
        /// </summary>
        public String Area
        { get; set; }
        
        /// <summary>
        /// Autoimplemeted property for PostCode
        /// </summary>
        public String PostCode
        { get; set; }
        
        /// <summary>
        /// Autoimplemeted property for state
        /// </summary>
        public String state
        { get; set; }

        /// <summary>
        /// Autoimplemeted property for Property Name
        /// </summary>
        public String Propertyname
        { get; set; }
        
        /// <summary>
        /// Autoimplemeted property for property Number
        /// </summary>
        public String propertyNo
        { get; set; }
        
        /// <summary>
        /// Autoimplemeted property for Street Number
        /// </summary>
        public String streetNo
        { get; set; }
        
        /// <summary>
        /// Autoimplemeted property for postal Code
        /// </summary>
        public int postalCode
        { get; set; }
        
        /// <summary>
        /// Autoimplemeted property for Area ID
        /// </summary>
        public string AreaID
        { get; set; }
        
        /// <summary>
        /// Autoimplemeted property for bond Price int value
        /// </summary>
        public int bond
        { get; set; }
        
        /// <summary>
        /// Autoimplemeted property for weely price int value
        /// </summary>
        public int weekprice
        { get; set; }
        
        /// <summary>
        /// Autoimplemeted property for rent from int value
        /// </summary>
        public int RFrom
        {get; set;}
        
        /// <summary>
        /// Autoimplemeted property for rent to int value
        /// </summary>
        public int RTo
        {get; set;}

        /// <summary>
        /// Auto Implemeted Property for Specific Price int value
        /// </summary>
        public int Price
        { get; set; }
        /// <summary>
        /// Auto Implemeted Property for Sell From Price
        /// </summary>
        
        /// <summary>
        /// Auto Implemeted Property for Sell From Price int value
        /// </summary>
        public int SFrom
        {get; set;}

        /// <summary>
        /// Auto Implemeted Property for Sell To Price int value
        /// </summary>
        public int STo
        { get; set; }

        //This Autoimplemeted property is for the Property Details, Property Type (House, Land, Villa etc.)
        /// <summary>
        /// Auto Implemeted Property for Property Type Value
        /// </summary>
        public string selectedValue
        { get; set; }

        /// <summary>
        /// Auto Implemeted Property for Bedroom Number
        /// </summary>
        public int BedroomNo
        { get; set; }

        /// <summary>
        /// Auto Implemeted Property for Bathroom Number
        /// </summary>
        public int BathroomNo
        { get; set; }

        /// <summary>
        /// Auto Implemeted Property for Number of Floors
        /// </summary>
        public int FloorNo
        { get; set; }

        /// <summary>
        /// Auto Implemeted Property for House Size
        /// </summary>
        public string HouseSize
        { get; set; }

        /// <summary>
        /// Auto Implemeted Property for Availability Status
        /// </summary>
        public string status
        { get; set; }

        /// <summary>
        /// Auto Implemeted Property for Property Type
        /// </summary>
        public string PropertyType
        { get; set; }

        /// <summary>
        /// Auto Implemeted Property for year of built
        /// </summary>
        public int yearofBuilt
        { get; set; }

        /// <summary>
        /// Auto Implemeted Property for Selected Dwellings
        /// </summary>
        public string DwellingSeleted
        { get; set; }

        //This part is used for storing the Description Details
        /// <summary>
        /// Auto Implemeted Property for Property Heading
        /// </summary>
        public string Heading
        { get; set; }

        /// <summary>
        /// Auto Implemeted Property for Property description
        /// </summary>
        public string Description
        { get; set; }

        /// <summary>
        /// Auto Implemeted Property for Contact FirstName
        /// </summary>
        public string FirstName
        { get; set; }

        /// <summary>
        /// Auto Implemeted Property for Contact LastName
        /// </summary>
        public string LastName
        { get; set; }

        /// <summary>
        /// Auto Implemeted Property for Contact Method
        /// </summary>
        public string ContactMethod
        { get; set; }

        /// <summary>
        /// Auto Implemeted Property for Contact Email
        /// </summary>
        public string Email
        { get; set; }

        /// <summary>
        /// Auto Implemeted Property for Contact Phone
        /// </summary>
        public string Phone
        { get; set; }

        /// <summary>
        /// Auto Implemeted Property for Land Details
        /// </summary>
        /// Auto Implemeted No. of Homes
        public int NumberHomes
        { get; set; }

        /// <summary>
        /// Auto Implemeted Property for Standard Land
        /// </summary>
        public int Standard
        { get; set; }

        /// <summary>
        /// Auto Implemeted Property for Non Standard Land
        /// </summary>
        public int NonStandard
        { get; set; }

        /// <summary>
        /// Auto Implemeted Property for Frontage
        /// </summary>
        public int Frontage
        { get; set; }

        /// <summary>
        /// Auto Implemeted Property for Depth
        /// </summary>
        public int Depth
        { get; set; }

        /// <summary>
        /// Auto Implemeted Property for Street Facing
        /// </summary>
        public string StreetFacing
        { get; set; }

        /// <summary>
        /// Auto Implemeted Property for Street Width
        /// </summary>
        public int StreetWidth
        { get; set; }

        /// <summary>
        /// Auto Implemeted Property for Land Status
        /// </summary>
        public string LandStatus
        {get; set;}

        /// <summary>
        /// Auto Implemented Property for Property ID
        /// </summary>
        public string PropertyID
        { get; set; }
        
#endregion Auto Implemented Properties for Mode Share, Rent and Sell

        DataSet ds = new DataSet();
        Advertisement advertise = new Advertisement();
        
        /// <summary>
        /// This function is used every time when the page loads or any postback happens
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            string mode = null;
            string TaskId = null;
            //Letting the User to fill in the proper details 
            //and then let the user to click the Confirm Button

            btnConfirm.Enabled = false;
            //These Error Panels are used for displaying the Errors for particular form

            #region Disabling the view of the Error Panels
            
            pnlSellErrors.Visible = false; //Sell Price Errors (Pricing Details)
            pnlAddressError.Visible = false; //Address Details Errors (Address Details)
            pnlRentPriceError.Visible = false; //Rent and Share Price Errors (Pricing Details)
            pnlPropertyDetailsError.Visible = false; //Property Details Errors (Property Details)
            pnlDescriptionError.Visible = false; //Property Description Errors (Description Details)
            pnlContactError.Visible = false; //Contact Details Errors (Contact Details)

            #endregion Disabling the view of the Error Panels

            //These are the panels for the the Property Details
            pnlLand.Visible = false;
            pnlLandSummary.Visible = false;

            try
            {
                //Getting the selected mode and TaskID from the URL
                mode = Request["Mode"].ToString();
                TaskId = Request["taskid"].ToString();
            }
            catch (Exception)
            {
                //Handling the exception, in case if occured
                Response.Redirect("~\\ErrorHandling\\ErrorPage.aspx");
            }

            //This section of code is used for Displaying the Property Ad Result.
            //It only executes if the user wants to edit the Property Ad
            if (Session["EditOption"].ToString() != "")
            {
                //Getting the Property ID
                PropertyID = Session["propertyID"].ToString();

                //Getting the Property Name
                Propertyname = Session["PropertyName"].ToString();
                txtPropertyName.Text = Propertyname;

                //Getting the Property No.
                propertyNo = Session["PropertyNo"].ToString();
                txtPropertyNo.Text = propertyNo;

                //Getting the Property Street No.
                streetNo = Session["StreetNo"].ToString();
                txtStreetNo.Text = streetNo;

                //Getting the Property StreetName
                streetname = Session["StreetName"].ToString();
                txtStreetName.Text = streetname;

                //Getting the Property Area Name
                Area = Session["Area"].ToString();
                txtArea.Text = Area;

                //Getting the Property Post Code
                PostCode = Session["PostCode"].ToString();
                txtPostCode.Text = PostCode;

                //Getting the Property State
                state = Session["State"].ToString();
                ddlState.SelectedValue = state;

                //Getting the AreaID for the Area's selected
                AreaID = Session["AreaID"].ToString();

                //Displaying the Address Detail summary
                lblAddressResponse.Text = Propertyname + "\n"
                                          + propertyNo + " " + streetNo + " " + streetname + "\n " +
                                          Area + ", " + PostCode + ", " + state;

                //This part is for the Pricing Details
                //Getting the Property Status for which the property was placed (Rent, Share, Sell)
                lblFor.Text = Session["PropertyStatus"].ToString();
                Session["status"] = lblFor.Text;

                switch (lblFor.Text)
                {
                    //If it was placed for Sale purpose
                    case "Sale":
                        {
                            try
                            {
                                Price = Convert.ToInt32(Session["FixedPrice"]);
                                txtSpecificPrice.Text = Price.ToString();
                            }
                            catch (Exception)
                            { Price = 0; }
                            try
                            {
                                SFrom = Convert.ToInt32(Session["PriceRangeFrom"]);
                                txtSellFrom.Text = SFrom.ToString();
                            }
                            catch (Exception) { SFrom = 0; }
                            try
                            {
                                STo = Convert.ToInt32(Session["PriceRangeTo"]);
                                txtSellTo.Text = STo.ToString();
                            }
                            catch (Exception) { STo = 0; }

                            if (Price != 0)
                            {
                                lblPropPrice.Text = "Rs. " + Convert.ToString(Price);
                                rdbSellSpecificPrice.Checked = true;
                            }
                            else if(SFrom != 0 || STo != 0)
                            {
                                lblPropPrice.Text = "Rs. " + Convert.ToString(SFrom) + " to " + Convert.ToString(STo);
                                rdbSellRange.Checked = true;
                            }
                            break;
                        }
                    //If it was placed for Renting purpose
                    case "Rent":
                        {
                            //Calling the function inorder to get the list of Price Details
                            //if the option is as Rent
                            GetPropertAdType();
                            break;
                        }
                    //If it was placed for Sharing purpose
                    case "Share":
                        {
                            //Calling the function inorder to get the list of Price Details
                            //if the option is as Share
                            GetPropertAdType();
                            break;
                        }
                    //If it was placed for Vacant purpose
                    case "Vacant":
                        {
                            //Calling the function inorder to get the list of Price Details
                            //if the option is as Share
                            GetPropertAdType();
                            break;
                        }
                }

                selectedValue = Session["PropertyType"].ToString();
                ddlPropertyType.SelectedValue = selectedValue;
                PropertyType = ddlPropertyType.SelectedValue;

                if (!selectedValue.Equals("Land"))
                {
                    try
                    {
                        BedroomNo = Convert.ToInt32(Session["BedroomNo"]);
                        txtBedRoomNo.Text = BedroomNo.ToString();
                    }
                    catch (Exception) { BedroomNo = 0; }
                    try
                    {
                        BathroomNo = Convert.ToInt32(Session["BathroomNo"]);
                        txtBathRoomNo.Text = BathroomNo.ToString();
                    }
                    catch (Exception) { BathroomNo = 0; }
                    try
                    {
                        FloorNo = Convert.ToInt32(Session["FloorNo"]);
                        txtFloorNo.Text = FloorNo.ToString();
                    }
                    catch (Exception) { FloorNo = 0; }
                    try
                    {
                        HouseSize = Session["HouseSize"].ToString();
                        txtHouseSize.Text = HouseSize.ToString();
                    }
                    catch (Exception) { HouseSize = ""; }
                    try
                    {
                        yearofBuilt = Convert.ToInt32(Session["YearBuilt"]);
                        txtYearBuilt.Text = yearofBuilt.ToString();
                    }
                    catch (Exception)
                    { yearofBuilt = 0; }

                    //Getting the Property Status of the Property
                    status = Session["PropertyStatus"].ToString();
                    switch (status)
                    {
                        //If the status is Rent
                        case "Rent":
                            {
                                rdbStatusRent.Checked = true;
                                break;
                            }
                        //If the status is Share
                        case "Share":
                            {
                                rdbStatusShare.Checked = true;
                                break;
                            }
                        //If the status is Sale
                        case "Sale":
                            {
                                rdbStatusSale.Checked = true;
                                break;
                            }
                        //If the status is Vacant
                        case "Vacant":
                            {
                                rdbStatusVacant.Checked = true;
                                break;
                            }
                    }

                    if (yearofBuilt != 0)
                    {
                        //Displaying the House summary
                        lblHouseSummary.Text = "Type:" + PropertyType + ", " + BedroomNo + " Bedroom, " + BathroomNo + " Bathroom, " + HouseSize + " House Size, " + status + " Status, " + yearofBuilt + " Year Built";
                    }
                    else
                    {
                        //Displaying the House summary
                        lblHouseSummary.Text = "Type:" + PropertyType + ", " + BedroomNo + " Bedroom, " + BathroomNo + " Bathroom, " + HouseSize + " House Size, " + status + " Status ";
                    }
                    pnlType.Visible = false;
                }
                else
                {
                    try
                    {
                        //Getting the Number of Homes
                        NumberHomes = Convert.ToInt32(Session["NumberHomes"]);
                        txtHomeNo.Text = NumberHomes.ToString();
                    }
                    catch (Exception) { NumberHomes = 0; }

                    //If the Sides of the property is 4 then its standard
                    if (Session["Standard"].ToString() != "")
                    {
                        try
                        {
                            //Getting the Standard of the property
                            Standard = Convert.ToInt32(Session["Standard"]);
                            rdbStandard.Checked = true;
                        }
                        catch (Exception) { Standard = 0; }
                    }
                        //If the sides of property is more than 4 or less than 4
                    else
                    {
                        try
                        {
                            //Getting the nonstandard no. of sides
                            NonStandard = Convert.ToInt32(Session["NonStandard"]);
                            rdbNonStandard.Checked = true;
                        }
                        catch (Exception) { NonStandard = 0; }
                    }
                    try
                    {
                        //Getting the frontage size of the property
                        Frontage = Convert.ToInt32(Session["Frontage"]);
                        txtFrontage.Text = Frontage.ToString();
                    }
                    catch (Exception) { Frontage = 0; }
                    try
                    {
                        //Getting the Depth size of the property
                        Depth = Convert.ToInt32(Session["Depth"]);
                        txtDepth.Text = Depth.ToString();
                    }
                    catch (Exception) { Depth = 0; }

                    //Getting the StreetFacing for the Property Side
                    StreetFacing = Session["StreetFacing"].ToString();
                    ddlStreetFacing.SelectedValue = StreetFacing;

                    try
                    {
                        StreetWidth = Convert.ToInt32(Session["StreetWidth"]);
                        txtStreetWidth.Text = StreetWidth.ToString();
                    }
                    catch (Exception)
                    { StreetWidth = 0; }

                    //Getting the Availablility Status for the property
                    status = Session["PropertyStatus"].ToString();
                    switch (status)
                    {
                        //If the status is Rent
                        case "Rent":
                            {
                                rdbLandRent.Checked = true;
                                break;
                            }
                        //If the status is Share
                        case "Share":
                            {
                                rdbLandShare.Checked = true;
                                break;
                            }
                        //If the status is Sale
                        case "Sale":
                            {
                                rdbLandSale.Checked = true;
                                break;
                            }
                        //If the status is Vacant
                        case "Vacant":
                            {
                                rdbLandVacant.Checked = true;
                                break;
                            }
                    }

                    //This is used for displaying the Land summary if the Type is Land
                    if (Session["NonStandard"].ToString() == "")
                    {
                        //If the Sides are NonStandard
                        lblLandSummary.Text = "Type: " + PropertyType + ", No. of Homes: " + NumberHomes + ", Sides: " + Standard + ", Frontage: " + Frontage + ", Depth: " + Depth +
                                    ", Street Facing: " + StreetFacing + ", StreetWidth: " + StreetWidth + ", Status: " + LandStatus;
                    }
                    else
                    {
                        //If the Sides are Standard
                        lblLandSummary.Text = "Type: " + selectedValue + ", No. of Homes: " + NumberHomes + ", Sides " + NonStandard + ", Frontage: " + Frontage + ", Depth: " + Depth +
                                ", Street Facing: " + StreetFacing + ", StreetWidth: " + StreetWidth + ", Status: " + LandStatus;
                    }
                    pnlType.Visible = false;
                }

                //Getting the Dwellings of the Property
                DwellingSeleted = Session["Dwellings"].ToString();
                lblDwellingSummary.Text = DwellingSeleted;

                //Getting the Heading of the Property
                Heading = Session["Heading"].ToString();
                txtpropHeading.Text = Heading;
                lblHeadingResult.Text = Heading;

                //Getting the Description of the Property
                Description = Session["Description"].ToString();
                edPropDesc.Content = Description;
                edDiscriptionSummary.Content = Description;

                //Getting the First name of the Advertiser
                FirstName = Session["FirstName"].ToString();
                txtFirstName.Text = FirstName;

                //Getting the Last name of the Advertiser
                LastName = Session["LastName"].ToString();
                txtLastName.Text = LastName;

                //Getting the Contact Method selected by the user
                ContactMethod = Session["ContactMethod"].ToString();
                switch (ContactMethod)
                {
                    case "Phone":
                        {
                            rdbPhone.Checked = true;
                            break;
                        }
                    case "Email":
                        {
                            rdbEmail.Checked = true;
                            break;
                        }
                }

                //Display the Email Contact Details
                Email = Session["Email"].ToString();
                txtEmail.Text = Email;

                //Display the Phone Contact Details
                Phone = Session["Phone"].ToString();
                txtPhone.Text = Phone;

                //Display the Contact Summary
                lblContactSummary.Text = "" + FirstName + ", " + LastName + ", " + ContactMethod + ", " + Email + ", " + Phone;
                Session["EditOption"] = "";
            }

            //Get the property Ad Type
            string propertyType = Session["propertyAdType"].ToString();

            switch (propertyType)
            {
                //For the Session["propertyAdType"] as mode "For Sell"
                #region For Mode as Sell
                case "ForSell":
                    {
                        pnlSell.Visible = true;
                        pnlRent.Visible = false;

                        rdbStatusSale.Visible = true;
                        rdbStatusShare.Visible = false;
                        rdbStatusRent.Visible = false;
                        rdbLandSale.Visible = true;
                        rdbLandShare.Visible = false;
                        rdbLandRent.Visible = false;

                        if (lblFor.Text != "")
                        {
                            pnlSell.Visible = false;
                            pnlPriceSummary.Visible = true;
                        }
                        else
                        {
                            pnlPriceSummary.Visible = false;
                            pnlSell.Visible = true;
                        }

                        if (lblAddressResponse.Text == "")
                        {
                            pnlPropertyAddressResponse.Visible = false;
                            pnlPAddress.Visible = true;
                        }
                        else
                        {
                            pnlPropertyAddressResponse.Visible = true;
                            pnlPAddress.Visible = false;
                        }
                        break;
                    }
                #endregion For Sell

                //For the Session["propertyAdType"] as mode "For Rent"
                #region For Mode as Rent
                case "ForRent":
                    {
                        pnlSell.Visible = false;
                        pnlRent.Visible = true;

                        rdbStatusSale.Visible = false;
                        rdbStatusShare.Visible = false;
                        rdbStatusRent.Visible = true;
                        rdbLandSale.Visible = false;
                        rdbLandShare.Visible = false;
                        rdbLandRent.Visible = true;

                        //Showing the Response Data of the user
                        if (lblFor.Text != "")
                        {
                            pnlRent.Visible = false;
                            pnlPriceSummary.Visible = true;
                        }
                        else
                        {
                            pnlRent.Visible = true;
                            pnlPriceSummary.Visible = false;
                        }
                        //Displaying the response what the user had types or asking for details
                        if (lblAddressResponse.Text == "")
                        {
                            pnlPropertyAddressResponse.Visible = false;
                            pnlPAddress.Visible = true;
                        }
                        else
                        {
                            pnlPropertyAddressResponse.Visible = true;
                            pnlPAddress.Visible = false;
                        }
                        break;
                    }
                #endregion For Mode as Rent

                //For the Session["propertyAdType"] as mode "For Share"
                #region For Mode as Share
                case "ForShare":
                    {
                        pnlSell.Visible = false;
                        pnlRent.Visible = true;

                        rdbStatusSale.Visible = false;
                        rdbStatusShare.Visible = true;
                        rdbStatusRent.Visible = false;
                        rdbLandSale.Visible = false;
                        rdbLandShare.Visible = true;
                        rdbLandRent.Visible = true;

                        //Showing the Response Data of the user
                        if (lblFor.Text != "")
                        {
                            pnlRent.Visible = false;
                            pnlPriceSummary.Visible = true;
                        }
                        else
                        {
                            pnlRent.Visible = true;
                            pnlPriceSummary.Visible = false;
                        }
                        //Displaying the response what the user had types or asking for details
                        if (lblAddressResponse.Text == "")
                        {
                            pnlPropertyAddressResponse.Visible = false;
                            pnlPAddress.Visible = true;
                        }
                        else
                        {
                            pnlPropertyAddressResponse.Visible = true;
                            pnlPAddress.Visible = false;
                        }
                        break;
                    }
                    #endregion For Mode as Share
            }

            //This Section is used for controlling the display of the summary for House, Dwelling and Contact

            #region Summary Controlling for House, Land, Dwelling, Contact and Description
            //Showing the House Summary
            //If there is house summary present

            #region House Summary
            if (lblHouseSummary.Text != "")
            {
                //Show the Summary Panel
                pnlHouseSummary.Visible = true;
                pnlHouse.Visible = false;
            }
            //If there is no house summary present
            else
            {
                //Hide the Summary Panel
                pnlHouseSummary.Visible = false;
                pnlHouse.Visible = true;
            }
            #endregion House Summary

            #region Dwelling Summary
            //If Dwelling Summary has some value
            if (lblDwellingSummary.Text != "")
            {
                pnlDwellingSummary.Visible = true;
                pnlDwellings.Visible = false;
                pnlNoValue.Visible = false;
            }
            //If Dwelling Summary has no value
            else
            {
                pnlDwellingSummary.Visible = false;
                pnlDwellings.Visible = true ;
                pnlNoValue.Visible = false;
            }
            #endregion Dwelling Summary

            #region Description Summary
            if (lblHeadingResult.Text != "")
            {
                pnlDescriptionSummary.Visible = true;
                pnlDescription.Visible = false;
            }
            else
            {
                pnlDescriptionSummary.Visible = false;
                pnlDescription.Visible = true;
            }
            #endregion Description Summary

            #region Contact Details Summary
            //This is for Showing the Summary result for the Contact Details..
            //Controlling the Panel Display on the basis on summary Value
            if (lblContactSummary.Text != "")
            {
                //Displaying the Summary
                pnlContactSummary.Visible = true;
                pnlContact.Visible = false;
            }
            else
            {
                //Displaying the Editable Mode
                pnlContactSummary.Visible = false;
                pnlContact.Visible = true;
            }
            #endregion Contact Details Summary

            #region Land Summary
            //Controlling the Land Summary
            if (ddlPropertyType.SelectedValue.Equals("Land"))
            {
                if (lblLandSummary.Text != "")
                {
                    //Show the Summary Panel
                    pnlLandSummary.Visible = true;
                    pnlLand.Visible = false;
                    pnlHouse.Visible = false;
                    pnlHouseSummary.Visible = false;
                }
                //If there is no house summary present
                else
                {
                    //Hide the Summary Panel
                    pnlLandSummary.Visible = false;
                    pnlLand.Visible = true;
                    pnlHouse.Visible = false;
                    pnlHouseSummary.Visible = false;
                }
            }
            #endregion Land Summary

            #endregion Summary Controlling for House, Land, Dwelling, Contact and Description

            //Checking whether the user has entered all the required fields
            //The confirm ad button will be enabled only if the user has entered all the required fields
            //in order to continue
            if (pnlPropertyAddressResponse.Visible == true && pnlPriceSummary.Visible == true)
            {
                if (pnlHouseSummary.Visible == true || pnlLandSummary.Visible == true)
                {
                    if (pnlDwellingSummary.Visible == true || pnlNoValue.Visible == true)
                    {
                        if (pnlDescriptionSummary.Visible == true)
                        {
                                //If all the required fields are entered then Enable the Confirm Button
                                btnConfirm.Enabled = true;
                        }
                    }
                }
            }
        }

        /// <summary>
        /// This functiuon is used for Getting the Price Value for the Rent and Share Status.
        /// It is executed on the page load function, while setting the Price Values.
        /// It only executes if the user wants to edit the Property Type
        /// </summary>
        #region Get the Price Values for Rent and Share (Called in Page_Load)
        protected void GetPropertAdType()
        {
            try
            {
                //Looking for the Weekly Price if set
                weekprice = Convert.ToInt32(Session["FixedPrice"]);
                txtRentweeklyPrice.Text = weekprice.ToString();
            }
                //If the Weekly price is not set handle the exception
            catch (Exception) { weekprice = 0; }
            try
            {
                //Looking for Price Range.
                RFrom = Convert.ToInt32(Session["PriceRangeFrom"]);
                txtRentFrom.Text = RFrom.ToString();
            }
                //If the Price Range not set then handle the exception.
            catch (Exception) { RFrom = 0; }
            try
            {
                //Looking for Price Range.
                RTo = Convert.ToInt32(Session["PriceRangeTo"]);
                txtRentTo.Text = RTo.ToString();
            }
            //If the Price Range not set then handle the exception.
            catch (Exception) { RTo = 0; }
            try
            {
                //Looking for Price Bond.
                bond = Convert.ToInt32(Session["Bond"]);
                txtRentBond.Text = bond.ToString();
            }
            //If the Price Bond not set then handle the exception.
            catch (Exception) { bond = 0; }

            //Here anyone option will fall. 
            //The application will force the user to have atleast one option to be filled
            if (weekprice != 0)
            {
                //If the Weekly Price is set then display it.
                lblPropPrice.Text = " Rs." + Convert.ToString(weekprice);
                lblBondSummary.Text = " Rs." + Convert.ToString(bond);
            }
            else
            {
                //If the Range Price is set then display it.
                if (RFrom != 0)
                {
                    lblPropPrice.Text = " Rs." + Convert.ToString(RFrom) + " to " + Convert.ToString(RTo);
                    lblBondSummary.Text = " Rs." + Convert.ToString(bond);
                }
            }
        }
        #endregion Get the Price Values for Rent and Share (Called in Page_Load)


        /// <summary>
        /// This function is used for saving the Property Address Details
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        #region Property Address Options
        protected void btnSavePropertyAddress_Click(object sender, EventArgs e)
        {
            try
            {
                streetname = txtStreetName.Text;
                Area = txtArea.Text;
                PostCode = txtPostCode.Text;
                state = ddlState.SelectedValue;
                //Checking for validation
                if (streetname.Trim() == "" || Area.Trim() == "" || PostCode.Trim() == "" || state.Trim() == "")
                {
                    //Showing the error if the required field is blank
                    pnlAddressError.Visible = true;
                    lblPropertyError.Text = "Please enter all the required details";
                }
                else
                {
                    pnlPAddress.Visible = false;
                    Propertyname = txtPropertyName.Text;
                    propertyNo = txtPropertyNo.Text;
                    streetNo = txtStreetNo.Text;
                    postalCode = System.Convert.ToInt32(PostCode);

                    //Checking whether the above address exists or not..
                    int response = advertise.CheckAddress(Area, PostCode, state);

                    if (response == 0)
                    {
                        AreaID = advertise.GetAreaID(Area, PostCode, state);
                        //Displaying the Property Address Summary
                        pnlPropertyAddressResponse.Visible = true;
                        pnlPAddress.Visible = false;
                        //Showing the Response of the user input
                        lblAddressResponse.Text = Propertyname + "\n"
                                                    + propertyNo + " " + streetNo + " " + streetname + "\n " +
                                                    Area + ", " + PostCode + ", " + state;
                        Session["PropertyName"] = Propertyname;
                        Session["PropertyNo"] = propertyNo;
                        Session["StreetName"] = streetname;
                        Session["StreetNo"] = streetNo;
                        Session["Area"] = Area;
                        Session["PostCode"] = PostCode;
                        Session["State"] = state;
                        Session["AreaID"] = AreaID;
                        string s = Session["PropertyName"].ToString();
                    }
                    else
                    {
                        pnlAddressError.Visible = true;
                        pnlPAddress.Visible = true;
                        lblPropertyError.Text = "This Address does not exists";
                    }
                }
            }//Displaying an error if occurred
            catch (Exception se)
            {
                string s = se.Message;
                pnlAddressError.Visible = true;
                lblPropertyError.Text = "Please Enter all the details";
            }
        }
        #endregion Property Address Options


        /// <summary>
        /// This function is used for Editing the property Address
        /// It Shows the Editing mode of the User Input (No Summary Displayed)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        #region Edit Property Address
        protected void btnEditPropertyAddress_Click(object sender, EventArgs e)
        {
            pnlPAddress.Visible = true;
            pnlPropertyAddressResponse.Visible = false;
        }
        #endregion Edit Property Address


        /// <summary>
        /// This function works in a two way as for saving information of Rent and Share
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        #region Rent and Share Save Details
        protected void btnRentSaveDetails_Click(object sender, EventArgs e)
        {
            lblBondPrice.Visible = true;
            try
            {
                //Checking which radio button is checked
                if (rdbRentWeekPrice.Checked == true)
                {
                    string weeklyPrice = txtRentweeklyPrice.Text;
                    string Bondprice = txtRentBond.Text;
                    //Check for validity
                    if (weeklyPrice.Trim() == "" || Bondprice.Trim() == "")
                    {
                        //Showing the generated error
                        pnlRentPriceError.Visible = true;
                        lblRentPriceError.Text = "Please enter valid Weekly or Bond price ";
                    }//If the value is valid
                    else
                    {
                        weekprice = Convert.ToInt32(weeklyPrice);
                        bond = Convert.ToInt32(Bondprice);

                        pnlRent.Visible = false;
                        //Displaing the Price Summary to the user
                        pnlPriceSummary.Visible = true;

                        //Checking the PropertyType for what the user selected
                        if (Session["propertyAdType"].Equals("ForRent")) //For Rent
                        {
                            lblFor.Text = "Rent";
                            Session["status"] = lblFor.Text;
                        }
                        else if (Session["propertyAdType"].Equals("ForShare")) //For Share
                        {
                            lblFor.Text = "Share";
                            Session["status"] = lblFor.Text;
                        }
                        lblPropPrice.Text = " Rs." + Convert.ToString(weekprice);
                        lblBondSummary.Text = " Rs." + Convert.ToString(bond);
                        
                        //Session variables for Rent and Share Price Option
                        Session["FixedPrice"] = weekprice;
                        Session["Bond"] = bond;
                    }
                }   
                //If Range radio button is checked
                else
                {
                    string rentFrom = txtRentFrom.Text;
                    string rentTo = txtRentTo.Text;
                    string Bondprice = txtRentBond.Text;
                    //Checking for validity
                    if (rentFrom.Trim() == "" || rentTo.Trim() == "" || Bondprice.Trim() == "")
                    {
                        pnlRentPriceError.Visible = true;
                        lblRentPriceError.Text = "Please enter the required valid field";
                        pnlRent.Visible = true;
                        pnlPriceSummary.Visible = false;
                    }
                    else
                    {
                        RFrom = Convert.ToInt32(rentFrom);
                        RTo = Convert.ToInt32(rentTo);
                        bond = Convert.ToInt32(Bondprice);

                        //If the Min. Price is larger than Max. Price
                        if (RFrom > RTo)
                        {
                            //Showing teh error message if Min. Price is larger than Max. Price
                            pnlRentPriceError.Visible = true;
                            lblRentPriceError.Text = "Min. Price must be small than Max. Price.";
                            pnlRent.Visible = true;
                            pnlPriceSummary.Visible = false;
                        }
                        else
                        {
                            pnlRent.Visible = false;
                            pnlPriceSummary.Visible = true;
                            pnlRentPriceError.Visible = false;
                            //Displaying the Summary for Pricing Details
                            //Checking the PropertyType for what the user selected
                            if (Session["propertyAdType"].Equals("ForRent")) //For Rent
                            {
                                lblFor.Text = "Rent";
                                Session["status"] = lblFor.Text;
                            }
                            else if (Session["propertyAdType"].Equals("ForShare")) //For Share
                            {
                                lblFor.Text = "Share";
                                Session["status"] = lblFor.Text;
                            }
                            lblPropPrice.Text = " Rs." + Convert.ToString(RFrom) + " to " + Convert.ToString(RTo);
                            lblBondSummary.Text = " Rs." + Convert.ToString(bond);

                            //Session variables for Pricing
                            //Session variables for Pricing Rent/Share
                            Session["PriceRangeFrom"] = RFrom;
                            Session["PriceRangeTo"] = RTo;
                            Session["Bond"] = bond;
                        }
                    }
                }
            }
            catch (Exception)
            {//Showing the error generated
                pnlRentPriceError.Visible = true;
                lblRentPriceError.Text = "Please enter the required details";
                pnlRent.Visible = true;
                pnlPriceSummary.Visible = false;
            }
        }

        /// <summary>
        /// This function is used for checked change property of the radio buttons
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void rdbRentWeekPrice_CheckedChanged(object sender, EventArgs e)
        {
            //Enabling and disabling some panel depending on the selection
            pnlRent.Visible = true;
            txtRentFrom.Enabled = false;
            txtRentTo.Enabled = false;
            txtRentweeklyPrice.Enabled = true;
            txtRentBond.Enabled = true;
            pnlPriceSummary.Visible = false;
        }

        /// <summary>
        /// This function is used for checked change property of the radio buttons
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void rdbRentalPriceRange_CheckedChanged(object sender, EventArgs e)
        {
            //Enabling and disabling some panel depending on the selection
            pnlRent.Visible = true;
            txtRentFrom.Enabled = true;
            txtRentTo.Enabled = true;
            txtRentweeklyPrice.Enabled = false;
            txtRentBond.Enabled = true;
            pnlPriceSummary.Visible = false;
        }
        #endregion Rent and Share Save Details

       
        /// <summary>
        /// This function is used for saving the Sell Property Details
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        #region Sell Price Options
        protected void btnSellSaveDetails_Click(object sender, EventArgs e)
        {
            lblBondPrice.Visible = false;
            try
            {
                //If Specific Price radio button is checked
                if (rdbSellSpecificPrice.Checked == true)
                {
                    string specificPrice = txtSpecificPrice.Text;
                    //Checking for validity
                    if (specificPrice.Trim() == "")
                    {
                        pnlSellErrors.Visible = true;
                        lblPriceError.Text = "Please enter valid Price";
                        pnlPriceSummary.Visible = false;
                        pnlSell.Visible = true;
                    }
                    else
                    {
                        //Displaying the Specific price details to the user
                        Price = Convert.ToInt32(specificPrice);
                        pnlSell.Visible = false;
                        pnlPriceSummary.Visible = true;
                        lblFor.Text = " Sale";
                        Session["status"] = lblFor.Text;
                        lblPropPrice.Text = "Rs. " + Convert.ToString(Price);
                        Session["FixedPrice"] = Price;
                    }
                }
                else
                {
                    //If range radio box is checked
                    string sellFrom = txtSellFrom.Text;
                    string sellTo = txtSellTo.Text;
                    //Checking for Validity
                    if (sellFrom.Trim() == "" || sellTo.Trim() == "")
                    {
                        pnlSellErrors.Visible = true;
                        lblPriceError.Text = "Please enter valid Price Range";
                    }
                    else
                    {
                        SFrom = Convert.ToInt32(sellFrom);
                        STo = Convert.ToInt32(sellTo);
                        //If the Min. Price is larger than Max. Price
                        if (SFrom > STo)
                        {
                            pnlSellErrors.Visible = true;
                            lblPriceError.Text = "Min. Price must be small than Max. Price.";
                            pnlPriceSummary.Visible = false;
                            pnlSell.Visible = true;
                        }
                        else
                        {
                            pnlSell.Visible = false;
                            pnlPriceSummary.Visible = true;
                            pnlSellErrors.Visible = false;
                            //Displaying the Summary for Pricing Details
                            lblFor.Text = " Sale";
                            Session["status"] = lblFor.Text;
                            lblPropPrice.Text = "Rs. " + Convert.ToString(SFrom) + " to " + Convert.ToString(STo);

                            //Session for Sale
                            Session["PriceRangeFrom"] = SFrom;
                            Session["PriceRangeTo"] = STo;
                        }
                    }
                }
            }
            //If some exceptopn occures during the execution..
            catch (Exception)
            {
                //Control the visibility
                pnlSellErrors.Visible = true;
                lblPriceError.Text = "Please enter the required details";
                pnlPriceSummary.Visible = false;
                pnlSell.Visible = true;
            }
        }

        /// <summary>
        /// This function checks the checked property of Radio Button for Selling Price
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void rdbSellSpecificPrice_CheckedChanged(object sender, EventArgs e)
        {
            //Enabling and disabling some panel depending on the selection
            pnlSell.Visible = true;
            txtSellFrom.Enabled = false;
            txtSellTo.Enabled = false;
            txtSpecificPrice.Enabled = true;
        }

        /// <summary>
        /// This function checks the checked property of Radio Button for Selling Price
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void rdbSellRange_CheckedChanged(object sender, EventArgs e)
        {
            //Enabling and disabling some panel depending on the selection
            pnlSell.Visible = true;
            txtSpecificPrice.Enabled = false;
            txtSellFrom.Enabled = true;
            txtSellTo.Enabled = true;
        }
        #endregion Sell Price Options


        /// <summary>
        /// This function is used for Editing the pricing details for all the property Modes
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        #region Edit Price for all the property modes
        protected void btnEditPrice_Click(object sender, EventArgs e)
        {
            //If the property Mode is Sell
            if (Session["propertyAdType"].Equals("ForSell"))
            {
                pnlSell.Visible = true;
                pnlPriceSummary.Visible = false;
            }
            //If the property Mode is Rent and Share
            else if ((Session["propertyAdType"].Equals("ForRent") || Session["propertyAdType"].Equals("ForShare")))
            {
                pnlSell.Visible = false;
                pnlRent.Visible = true;
                pnlPriceSummary.Visible = false;
            }
        }
        #endregion Edit Price for all the property modes


        /// <summary>
        /// This function is used for Showing the property type panels assosiated to what user
        /// has selected.
        /// It includes Home, Land, Villa, Apartment, Studio
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        #region Select Property Type (Property Type)
        protected void ddlPropertyType_SelectedIndexChanged(object sender, EventArgs e)
        {
            //Getting the selected value of the drop down list
            selectedValue = ddlPropertyType.SelectedValue;
            //For the selected value..
            switch(selectedValue)
            {
                    //If value selected is "Select---"
                case "Select---":
                    {
                        pnlPropertyDetailsError.Visible = true;
                        lblDetailsErrorMessage.Text = "Please select the property type";
                        pnlHouse.Visible = true;
                        break;
                    }
                //If value selected is "House"
                case "House":
                    {
                        pnlHouse.Visible = true;
                        pnlLand.Visible = false;
                        pnlHouseSummary.Visible = false;
                        break;
                    }
                //If value selected is "Land"
                case "Land":
                    {
                        pnlHouse.Visible = false;
                        pnlLand.Visible = true;
                        pnlHouseSummary.Visible = false;
                        break;
                    }
                //If value selected is "Villa"
                case "Villa":
                    {
                        pnlHouse.Visible = true;
                        pnlLand.Visible = false;
                        pnlHouseSummary.Visible = false;
                        break;
                    }
                //If value selected is "Studio"
                case "Studio":
                    {
                        pnlHouse.Visible = true;
                        pnlLand.Visible = false;
                        pnlHouseSummary.Visible = false;
                        break;
                    }
                //If value selected is "Apartment"
                case "Flat/Apartment":
                    {
                        pnlHouse.Visible = true;
                        pnlLand.Visible = false;
                        pnlHouseSummary.Visible = false;
                        break;
                    }
                //This the default value.
                default:
                    {
                        break;
                    }
                }
        }
        #endregion Select Property Type (Property Type)


        /// <summary>
        /// This function is used for saving the house Details
        /// It save the information as: No. of Bedrooms, Bathrooms, Floors, YearBuilt etc
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        #region House Save Details
        protected void btnHouseDetails_Click(object sender, EventArgs e)
        {
            Boolean condition = false;
            try
            {
                //getting the values from each text boxes
                string bedroomNo = txtBedRoomNo.Text;
                string bathroomNo = txtBathRoomNo.Text;
                string floorNo = txtFloorNo.Text;
                string houseSize = txtHouseSize.Text;
                string YearBuilt = txtYearBuilt.Text;

                //Getting the Property type selected by the user
                string selectedvalue = ddlPropertyType.SelectedValue;
                
                //If the Selected type is other than Selected..
                if (selectedvalue != "Select---")
                {
                    //Checking for Validity
                    if (bedroomNo.Trim() == "" || bathroomNo.Trim() == "" || floorNo.Trim() == "" || houseSize.Trim() == "")
                    {
                        //Displaying the Error Information and Enabling or disabling teh visibility accordingly
                        condition = false;
                        pnlPropertyDetailsError.Visible = true;
                        lblDetailsErrorMessage.Text = "Please enter the valid required fields.";
                        pnlHouse.Visible = true;
                        pnlHouseSummary.Visible = false;
                    }
                    else
                    {
                        //If the data required are valid
                        condition = true;
                        //Convert all the data to int which is required by the database
                        BedroomNo = Convert.ToInt32(bedroomNo);
                        BathroomNo = Convert.ToInt32(bathroomNo);
                        FloorNo = Convert.ToInt32(floorNo);
                        HouseSize = houseSize;
                        PropertyType = selectedvalue;

                        //If the YearBuilt is null or blank
                        if (YearBuilt.Trim() == "")
                        {
                            YearBuilt = "Not Provided";
                        }
                        else
                        {   //Get the int value of year Built
                            yearofBuilt = Convert.ToInt32(YearBuilt);
                        }

                        //Checking which Availability Ststus has been Checked
                        //If Vacant is Checked
                        if (rdbStatusVacant.Checked)
                        {
                            status = "Vacant";
                        }
                        //If Rent is Checked
                        else if (rdbStatusRent.Checked)
                        {
                            status = "Rent";
                        }
                        //If Status is Checked
                        else if (rdbStatusSale.Checked)
                        {
                            status = "Sale";
                        }
                        //If Share is Checked
                        else if (rdbStatusShare.Checked)
                        {
                            status = "Share";
                        }
                    }

                    //If all the details are provide and valid
                    if (condition == true)
                    {
                        //Display the Summary Result
                        pnlHouseSummary.Visible = true;
                        pnlPropertyType.Visible = false;
                        if (yearofBuilt != 0)
                        {
                            lblHouseSummary.Text = "Type:" + PropertyType + ", " + BedroomNo + " Bedroom, " + BathroomNo + " Bathroom, " + HouseSize + " House Size, " + status + " Status, " + yearofBuilt+ " Year Built";
                            //Session variables for Property Details
                            Session["PropertyType"] = PropertyType;
                            Session["BedroomNo"] = BedroomNo;
                            Session["BathroomNo"] = BathroomNo;
                            Session["FloorNo"] = FloorNo;
                            Session["HouseSize"] = HouseSize;
                            Session["YearBuilt"] = yearofBuilt;
                            Session["PropertyStatus"] = status;
                        }
                        else
                        {
                            lblHouseSummary.Text = "Type:" + PropertyType + ", " + BedroomNo + " Bedroom, " + BathroomNo + " Bathroom, " + HouseSize + " House Size, " + status + " Status ";
                            //Session variables for Property Details
                            Session["PropertyType"] = PropertyType;
                            Session["BedroomNo"] = BedroomNo;
                            Session["BathroomNo"] = BathroomNo;
                            Session["FloorNo"] = FloorNo;
                            Session["HouseSize"] = HouseSize;
                            Session["YearBuilt"] = yearofBuilt;
                            Session["PropertyStatus"] = status;

                        }
                        pnlHouse.Visible = false;
                    }
                }
                else
                {   //If the Property Type is not selected then...
                    //Show the error message
                    condition = false;
                    pnlPropertyDetailsError.Visible = true;
                    lblDetailsErrorMessage.Text = "Please enter the valid required fields.";
                    pnlHouse.Visible = true;
                    pnlHouseSummary.Visible = false;
                }
            }
            catch (Exception)
            {
                //In case any exception occurs then 
                condition = false;
                pnlPropertyDetailsError.Visible = true;
                lblDetailsErrorMessage.Text = "Please enter the valid details";
                pnlHouse.Visible = true;
            }
        }
        #endregion House Save Details

        
        /// <summary>
        /// This finction is used for saving the Land Details
        /// It save the information such as: Land Size, Standard or Nonstandard etc
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        #region Land Save Details
        protected void btnLandDetails_Click(object sender, EventArgs e)
        {
            pnlHouseSummary.Visible = false;

            //Getting the details of what the user has typed
            string HouseNo = txtHomeNo.Text;
            string nonStandard = txtNonStandard.Text;
            string frontage = txtFrontage.Text;
            string depth = txtDepth.Text;
            string streetFacing = ddlStreetFacing.SelectedValue;
            string streetWidth = txtStreetWidth.Text;

            try
            {
                //If the user has selected "Land" as a property Type
                if (!ddlStreetFacing.SelectedValue.Equals("Select---"))
                {
                    //Checking if the Standard option is checked or not
                    if (rdbStandard.Checked == true)
                    {
                        //Check for Validity.. Looking for some data in required fields
                        if (frontage.Trim() == "" || depth.Trim() == "")
                        {
                            //Show the error message; to fill the details
                            pnlPropertyDetailsError.Visible = true;
                            lblDetailsErrorMessage.Text = "Please enter the valid required details.";
                            pnlLand.Visible = true;
                            pnlLandSummary.Visible = false;                
                        }
                            //If the entered data is valid then show the summary details
                        else
                        {
                            //Getting the land status
                            #region Land Status
                            if (rdbLandRent.Checked == true)
                            {
                                LandStatus = "Rent";
                            }
                            else if (rdbLandSale.Checked == true)
                            {
                                LandStatus = "Sale";
                            }
                            else if (rdbLandShare.Checked == true)
                            {
                                LandStatus = "Share";
                            }
                            else if (rdbLandVacant.Checked == true)
                            {
                                LandStatus = "Vacant";
                            }
                            #endregion Land Status
                            //If No house no. is entered the set to 0
                            if (HouseNo.Trim() == "")
                            {
                                NumberHomes = 0;
                            }
                            else
                            {
                                //Get the House No.
                                NumberHomes = Convert.ToInt32(HouseNo);
                            }
                            //Convert the values in a required format required by database
                            Standard = 4;
                            Frontage = Convert.ToInt32(frontage);
                            Depth = Convert.ToInt32(depth);
                            StreetFacing = ddlStreetFacing.SelectedValue;

                            //getting the street width 
                            if (streetWidth.Trim() == "")
                            {
                                StreetWidth = 0;
                            }
                            else
                            {
                                StreetWidth = Convert.ToInt32(streetWidth);
                            }

                            //Show the summary containing the information such as: Type, No. of Home, StreetFacing etc.
                            PropertyType = "Land";
                            pnlLandSummary.Visible = true;
                            lblLandSummary.Text = "Type: " + PropertyType + ", No. of Homes: " + NumberHomes + ", Sides: " + Standard + ", Frontage: " + Frontage + ", Depth: " + Depth +
                                ", Street Facing: " + StreetFacing + ", StreetWidth: " + StreetWidth + ", Status: " + LandStatus;

                            //Session variables for Land Status
                            Session["PropertyType"] = PropertyType;
                            Session["NumberHomes"] = NumberHomes;
                            Session["Standard"] = Standard;
                            Session["Frontage"] = Frontage;
                            Session["Depth"] = Depth;
                            Session["StreetFacing"] = StreetFacing;
                            Session["StreetWidth"] = StreetWidth;
                            Session["PropertyStatus"] = LandStatus;
                            
                            pnlHouse.Visible = false;
                            pnlLand.Visible = false;
                            pnlPropertyDetailsError.Visible = false;
                            pnlPropertyType.Visible = false;
                        }
                    }
                        //If Non standard option is checked then..
                    else if (rdbNonStandard.Checked == true)
                    {
                        //Checking for validity
                        if (nonStandard.Trim() == "")
                        {
                            //Show the error message
                            pnlPropertyDetailsError.Visible = true;
                            lblDetailsErrorMessage.Text = "Please enter the valid required details.";
                            pnlLand.Visible = true;
                            pnlLandSummary.Visible = false;
                        }
                            //If the entered required details are valid
                        else
                        {
                            //Set the Land Status
                            #region Land Status
                            //If the Rent Type is checked
                            if (rdbLandRent.Checked == true)
                            {
                                LandStatus = "Rent";
                            }
                            //If the Sale Type is checked
                            else if (rdbLandSale.Checked == true)
                            {
                                LandStatus = "Sale";
                            }
                            //If the Share Type is checked
                            else if (rdbLandShare.Checked == true)
                            {
                                LandStatus = "Share";
                            }
                            //If the Vacant Type is checked
                            else if (rdbLandVacant.Checked == true)
                            {
                                LandStatus = "Vacant";
                            }
                            #endregion Land Status

                            //Getting the No. of Houses on Land
                            //If no House No. has been entered
                            if (HouseNo.Trim() == "")
                            {
                                NumberHomes = 0;
                            }
                            else
                            {
                                //If house no. has been entered
                                NumberHomes = Convert.ToInt32(HouseNo);
                            }
                            //Converting to the values required by the database
                            NonStandard = Convert.ToInt32(nonStandard);
                            Frontage = Convert.ToInt32(frontage);
                            Depth = Convert.ToInt32(depth);
                            StreetFacing = ddlStreetFacing.SelectedValue;

                            if (streetWidth.Trim() == "")
                            {
                                StreetWidth=0;
                            }
                            else
                            {
                                StreetWidth = Convert.ToInt32(streetWidth);
                            }

                            //Show the Summary Details of the Land Information
                            PropertyType = "Land";
                            pnlLandSummary.Visible = true;
                            pnlPropertyType.Visible = false;
                            //Showing the summary details
                            lblLandSummary.Text = "Type: " + selectedValue + ", No. of Homes: " + NumberHomes + ", Sides " + NonStandard + ", Frontage: " + Frontage + ", Depth: " + Depth +
                                ", Street Facing: " + StreetFacing + ", StreetWidth: " + StreetWidth + ", Status: " + LandStatus;

                            //Session variables for Land Status
                            Session["PropertyType"] = PropertyType;
                            Session["NumberHomes"] = NumberHomes;
                            Session["NonStandard"] = NonStandard;
                            Session["Frontage"] = Frontage;
                            Session["Depth"] = Depth;
                            Session["StreetFacing"] = StreetFacing;
                            Session["StreetWidth"] = StreetWidth;
                            Session["PropertyStatus"] = LandStatus;

                            pnlLand.Visible = false;
                            pnlHouse.Visible = false;
                            pnlPropertyDetailsError.Visible = false;
                            pnlPropertyType.Visible = false;
                        }
                    }
                }
                    //If the "Select---" option is selected 
                else
                {
                    //Show the error message
                    pnlPropertyDetailsError.Visible = true;
                    lblDetailsErrorMessage.Text = "Please select the street facing.";
                    pnlLand.Visible = true;
                    pnlLandSummary.Visible = false;
                    pnlHouseSummary.Visible = false;
                    pnlHouse.Visible = false;
                    pnlPropertyType.Visible = true;
                }
            }
                //If any exception occurs then show some error message
            catch (Exception)
            {
                //Showing the Error panel
                pnlPropertyType.Visible = true;
                pnlHouse.Visible = false;
                pnlPropertyDetailsError.Visible = true;
                lblDetailsErrorMessage.Text = "Please select the street facing.";
                pnlLand.Visible = true;
                pnlLandSummary.Visible = false;
                pnlHouseSummary.Visible = false;
            }
        }
        #endregion Land Save Details

        
        /// <summary>
        /// This function is used for Editing the Saved House Details or Land Save Details
        /// It Displays the Editing mode and hides the Summary
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        #region Edit House Summary and Land Summary
        protected void btnEditHouse_Click(object sender, EventArgs e)
        {
            //It controls the visibility of the appropriate panels
            pnlPropertyType.Visible = true;

            string select=ddlPropertyType.SelectedValue;
            if (select.Equals("Land"))
            {
                pnlHouseSummary.Visible = false;
                pnlLand.Visible = true;
                pnlLandSummary.Visible = false;
                pnlHouse.Visible = false;
            }
            else
            {
                pnlHouseSummary.Visible = false;
                pnlHouse.Visible = true;
                pnlLand.Visible = false;
                pnlLandSummary.Visible = false;
            }
        }
        #endregion Edit House Summary

        
        /// <summary>
        /// This function is used for saving the Dwelling Details, of what the user selected.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        #region Save Dwelling Details
        protected void btnSaveDwelling_Click(object sender, EventArgs e)
        {
            DwellingSeleted = "";
            //Creating the List for storing the selected Dwelling
            List<String> selecteddwelling = new List<string>();
            
            //Get all the Values from Dwelling Area 1
            for (int i = 0; i <= chkDwellings1.Items.Count - 1; i++)
            {
                //Get all the selected Values from Dwelling Area 1
                if ((chkDwellings1.Items[i].Selected) == true)
                {
                    string dwellings = chkDwellings1.Items[i].Value;

                    selecteddwelling.Add(dwellings);
                    //Store the Dwellings in DwellingSelected
                    DwellingSeleted += dwellings+", ";
                }
            }
            //Get all the Values from Dwelling Area 2
            for (int i = 0; i <= chkDwelling2.Items.Count - 1; i++)
            {
                //Get all the selected Values from Dwelling Area 2
                if ((chkDwellings1.Items[i].Selected) == true)
                {
                    string dwellings = chkDwelling2.Items[i].Value;

                    //Store the Dwellings in DwellingSelected
                    selecteddwelling.Add(dwellings);
                    DwellingSeleted += dwellings + ", ";
                }
            }
            //Get all the Values from Dwelling Area 3
            for (int i = 0; i <= chkDwelling3.Items.Count - 1; i++)
            {
                //Get all the selected Values from Dwelling Area 3
                if ((chkDwellings1.Items[i].Selected) == true)
                {
                    string dwellings = chkDwelling3.Items[i].Value;

                    //Store the Dwellings in DwellingSelected
                    selecteddwelling.Add(dwellings);
                    DwellingSeleted += dwellings+", ";
                }
            }

            string selectedValues = DwellingSeleted;

            //If no Dwelling has been selected
            if (selectedValues == null)
            {
                //Control the visibility..
                pnlDwellingSummary.Visible = false;
                pnlDwellings.Visible = false;
                pnlNoValue.Visible = true;
                Session["Dwellings"] = "";
            }
            //If there are some values in DwellingSelected
            else
            {
               //Show the summary for the Dwellings
                pnlDwellingSummary.Visible = true;
                lblDwellingSummary.Text = selectedValues;

                //Session variables for Dwelling Details
                Session["Dwellings"] = selectedValues;

                pnlDwellings.Visible = false;
                pnlNoValue.Visible = false;
            }
        }

        #endregion Save Dwelling Details

        
        /// <summary>
        /// This function is used for Displaying the Dwelling Selection in Editable mode
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        #region Edit Dwelling
        protected void btnEditDwelling_Click(object sender, EventArgs e)
        {
            //Controlling the visibility to show the Editable Mode
            pnlDwellingSummary.Visible = false;
            pnlNoValue.Visible = false;
            pnlDwellings.Visible = true ;
        }
        #endregion Edit Dwelling

        
        /// <summary>
        /// This function is used for saving the description result
        /// This includes the Heading and Description
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        #region Save Property Description
        protected void btnSaveDescription_Click(object sender, EventArgs e)
        {
            edDiscriptionSummary.Enabled = false;
            try
            {
                //Getting the value of Heading and Description
                string heading = txtpropHeading.Text;
                string desc = edPropDesc.Content;
                //If user has entered no heading (Required Field)
                if (heading.Trim() == "")
                {
                    //Show the Error Message
                    pnlDescriptionError.Visible = true;
                    lblDescriptionError.Text = "Please enter the required Fields";
                }
                //If user has entered heading (Required Field)
                else
                {
                    //Control the visibility of the Panels and show the save result
                    Heading = heading;
                    pnlDescriptionSummary.Visible = true;
                    lblHeadingResult.Text = Heading;
                    edDiscriptionSummary.Content = desc;
                    Description = desc;
                    edDiscriptionSummary.Enabled = false;
                    //Session variables for Property Description
                    Session["Heading"] = Heading;
                    Session["Description"] = Description;

                    pnlDescription.Visible = false;
                }
            }
                //If any exception occurred
            catch (Exception)
            {
                //Show the error message
                pnlDescriptionError.Visible = true;
                lblDescriptionError.Text = "Please enter the valid details";
            }
        }
        #endregion Save Property Description

        
        /// <summary>
        /// This function is used for showing the editable mode of Description Panel
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        #region Edit Description Details
        protected void btnEditDescription_Click(object sender, EventArgs e)
        {
            //Control the visibility of the Description
            pnlDescriptionSummary.Visible = false;
            pnlDescription.Visible = true;
        }

        #endregion Edit Description Details

        
        /// <summary>
        /// Save Contact Details
        /// It stores the First name, Last name, Email, Phone and contact Method
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        #region Save Contact Details
        protected void btnSaveContact_Click(object sender, EventArgs e)
        {
            try
            {
                //Getting the Details from the form
                string fname = txtFirstName.Text;
                string lname = txtLastName.Text;
                string contactMethod = null;

                //Setting the contact method on the basis of selection
                //If the selection is Email
                if (rdbEmail.Checked == true)
                {
                    contactMethod = "Email";
                }
                //If the selection is Phone
                else if (rdbPhone.Checked == true)
                {
                    contactMethod = "Phone";
                }

                string email = txtEmail.Text;
                string phone = txtPhone.Text;

                //Checking for Validity
                if (fname.Trim() == "" || lname.Trim() == "" || email.Trim() == "" || phone.Trim() == "")
                {
                    //If no data found show the error
                    pnlContactError.Visible = true;
                    lblContactError.Text = "Please enter the required details";
                    pnlContact.Visible = true;
                    pnlContactSummary.Visible = false;
                }
                //If no errors generated then Display the Summary
                else
                {
                    //Storing teh valid details in Properties
                    FirstName = fname;
                    LastName = lname;
                    Email = email;
                    Phone = phone;
                    ContactMethod = contactMethod;
                    pnlContactSummary.Visible = true;
                    //Display the Summary Details
                    lblContactSummary.Text = "" + FirstName + ", " + LastName + ", " + ContactMethod + ", " + Email + ", " + Phone;

                    //Session variables for Contact Details
                    Session["FirstName"] = FirstName;
                    Session["LastName"] = LastName;
                    Session["ContactMethod"] = ContactMethod;
                    Session["Email"] = Email;
                    Session["Phone"] = Phone;

                    pnlContact.Visible = false;
                    pnlContactError.Visible = false;
                }
            }
                //If some exception occurs then show the error message
            catch (Exception)
            {
                //Showing the error
                pnlContactError.Visible = true;
                lblContactError.Text = "Please enter the required valid details";
                pnlContact.Visible = true;
                pnlContactSummary.Visible = false;
            }
        }
        #endregion Save Contact Details

        
        /// <summary>
        /// This function is used for editing the contact details
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        #region Edit Contacts
        protected void btnEditContacts_Click(object sender, EventArgs e)
        {
            //Displaying the Contact editable mode
            pnlContactSummary.Visible = false;
            pnlContact.Visible = true;
        }
        #endregion Edit Contacts

        //Below Functions are for the Image Upload Part

        #region Image Section
        protected void Button1_Click(object sender, EventArgs e)
        {
            div2.Visible = true;
            String TaskId = Request["taskid"].ToString();
            String propImagesLOC = Server.MapPath("../propImages");
            String tempFolderLOC = propImagesLOC + "\\" + Session["TaskID"].ToString() + "\\";

            if (!System.IO.Directory.Exists(propImagesLOC))
            { System.IO.Directory.CreateDirectory(propImagesLOC); }

            //creating folder by the name of task_id

            if (!System.IO.Directory.Exists(propImagesLOC + "/" + Session["TaskID"].ToString()))
            { System.IO.Directory.CreateDirectory(propImagesLOC + "/" + Session["TaskID"].ToString()); }

            HttpFileCollection uploadFilCol = Request.Files;
            for (int i = 0; i < uploadFilCol.Count; i++)
            {
                HttpPostedFile file = uploadFilCol[i];
                string fileExt = Path.GetExtension(file.FileName).ToLower();
                string fileName = Path.GetFileName(file.FileName);
                if (fileName != string.Empty)
                {
                    try
                    {
                        if (fileExt == ".jpg" || fileExt == ".gif" || fileExt == ".bmp" || fileExt == ".jpeg" || fileExt == ".png")
                        {

                            if (i == 0)
                            {
                                Image1.ImageUrl = "~/propImages/" + Session["TaskID"].ToString() + "/" + (i + 1) + ".jpg";
                                file.SaveAs(tempFolderLOC + (i + 1) + ".jpg");

                                LinkButton1.Visible = true;
                            }
                            if (i == 1)
                            {
                                file.SaveAs(tempFolderLOC + (i + 1) + ".jpg");
                                Image2.ImageUrl = "~/propImages/" + Session["TaskID"].ToString() + "/" + (i + 1) + ".jpg";
                                LinkButton2.Visible = true;
                            }
                            if (i == 2)
                            {
                                file.SaveAs(tempFolderLOC + (i + 1) + ".jpg");
                                Image3.ImageUrl = "~/propImages/" + Session["TaskID"].ToString() + "/" + (i + 1) + ".jpg";
                                LinkButton3.Visible = true;
                            }
                            if (i == 3)
                            {
                                file.SaveAs(tempFolderLOC + (i + 1) + ".jpg");
                                Image4.ImageUrl = "~/propImages/" + Session["TaskID"].ToString() + "/" + (i + 1) + ".jpg";
                                LinkButton4.Visible = true;
                            }
                            if (i == 4)
                            {
                                file.SaveAs(tempFolderLOC + (i + 1) + ".jpg");
                                Image5.ImageUrl = "~/propImages/" + Session["TaskID"].ToString() + "/" + (i + 1) + ".jpg";
                                LinkButton5.Visible = true;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
            }
        }
        #endregion Image Section

        #region Image Section
        protected void ButtonMore_Click(object sender, EventArgs e)
        {
            //string file = Server.MapPath("./") + "propImages/1.jpg";
            //System.IO.File.Delete(file);
        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            String TaskId = Request["taskid"].ToString();

            string file = Server.MapPath("../") + "propImages\\" + TaskId + "\\1.jpg";
            System.IO.File.Delete(file);
            LinkButton1.Visible = false;
        }

        protected void LinkButton2_Click(object sender, EventArgs e)
        {
            String TaskId = Request["taskid"].ToString();

            string file = Server.MapPath("../") + "propImages\\" + TaskId + "\\2.jpg";
            System.IO.File.Delete(file);
            LinkButton2.Visible = false;
        }

        protected void LinkButton3_Click(object sender, EventArgs e)
        {
            String TaskId = Request["taskid"].ToString();

            string file = Server.MapPath("../") + "propImages\\" + TaskId + "\\3.jpg";
            System.IO.File.Delete(file);
            LinkButton3.Visible = false;
        }

        protected void LinkButton4_Click(object sender, EventArgs e)
        {
            String TaskId = Request["taskid"].ToString();

            string file = Server.MapPath("../") + "propImages\\" + TaskId + "\\4.jpg";
            System.IO.File.Delete(file);
            LinkButton4.Visible = false;
        }

        protected void LinkButton5_Click(object sender, EventArgs e)
        {
            String TaskId = Request["taskid"].ToString();

            string file = Server.MapPath("../") + "propImages\\" + TaskId + "\\5.jpg";
            System.IO.File.Delete(file);
            LinkButton5.Visible = false;
        }
        #endregion Image Section


        /// <summary>
        /// This function is used for Confirming the Property Ad
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnConfirm_Click(object sender, EventArgs e)
        {
            //Redirecting the user to confirm the Property Ad
            Response.Redirect("~//ManageAds//ConfirmAd.aspx");
        }
    }
}

